﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyEmployees.Models;
using MyEmployees.BLL;

namespace MyEmployees
{
    public partial class FrmUpdate : Form
    {
        int employeeID;
        EmployeeManage empManage;
        Employees emp;
        public FrmUpdate(int empID)
        {
            InitializeComponent();
            employeeID = empID;
            empManage = new EmployeeManage();
        }

        private void FrmUpdate_Load(object sender, EventArgs e)
        {
            lblID.Text = employeeID.ToString();//显示待修改雇员的编号
            emp = new Employees();
            emp = empManage.SearchById(employeeID);

            txtLN.Text = emp.LastName;
            txtFN.Text = emp.FirstName;
            txtCountry.Text = emp.Country;
            dtpBirthday.Value = emp.Birthday;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //恢复原来的数据
            txtLN.Text = emp.LastName;
            txtFN.Text = emp.FirstName;
            txtCountry.Text = emp.Country;
            dtpBirthday.Value = emp.Birthday;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Employees newemp = new Employees();
            newemp.EmployeeID = Convert.ToInt16(lblID.Text);
            newemp.FirstName = txtFN.Text;
            newemp.LastName = txtLN.Text;
            newemp.Country = txtCountry.Text;
            newemp.Birthday =dtpBirthday.Value;

            //保存修改
            if (empManage.SaveEdit(newemp))
            {
                MessageBox.Show("修改成功");
                this.Close();
            }
            else
                MessageBox.Show("保存失败");

        }
    }
}
